package com.nuc.wxh.vaccine_appointment.vaccines.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuc.wxh.vaccine_appointment.vaccines.entity.AllVaccine;
import com.nuc.wxh.vaccine_appointment.vaccines.entity.HospitalVaccine;
import com.nuc.wxh.vaccine_appointment.vaccines.entity.vo.HospitalVaccineVo;
import com.nuc.wxh.vaccine_appointment.vaccines.mapper.HospitalVaccineMapper;
import com.nuc.wxh.vaccine_appointment.vaccines.service.HospitalVaccineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 医院疫苗设置 服务实现类
 * </p>
 *
 * @author 王鑫浩
 * @since 2021-03-10
 */
@Service
public class HospitalVaccineServiceImpl extends ServiceImpl<HospitalVaccineMapper, HospitalVaccine> implements HospitalVaccineService {

    @Override
    public Page<HospitalVaccine> selectPage(Page<HospitalVaccine> pageParam, HospitalVaccineVo hospitalvaccineVo) {
        //条件构造器
        QueryWrapper<HospitalVaccine> wrapper = new QueryWrapper<>();
        //普通的排序分页查询
        if (hospitalvaccineVo == null) {
            return baseMapper.selectPage(pageParam,wrapper);
        }
        //获取对象参数
        String vaccineName = hospitalvaccineVo.getVaccineName();
        String vaccineManufacturer = hospitalvaccineVo.getVaccineManufacturer();
        String vaccineClassification = hospitalvaccineVo.getVaccineClassification();
        String hospitalId = hospitalvaccineVo.getHospitalId();
        //条件
        if (!StringUtils.isEmpty(hospitalId)) {
            wrapper.likeRight("hospital_id", hospitalId);
        }
        if (!StringUtils.isEmpty(vaccineName)) {
            wrapper.likeRight("vaccine_name", vaccineName);
        }
        if (!StringUtils.isEmpty(vaccineManufacturer)) {
            wrapper.likeRight("vaccine_manufacturer", vaccineManufacturer);
        }
        if (!StringUtils.isEmpty(vaccineClassification)) {
            wrapper.likeRight("vaccine_classification", vaccineClassification);
        }
        if (!StringUtils.isEmpty(hospitalId)) {
            wrapper.likeRight("hospital_id", hospitalId);
        }

        return baseMapper.selectPage(pageParam, wrapper);
    }
}
